package com.fred.colorpicker

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope

class Main1Activity : ComponentActivity(), CoroutineScope by MainScope() {

    private val colorPicker by lazy {
        ColorPickerMenu()
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme{

                Column(modifier = Modifier.padding(0.dp)) {
                    val rectColor = remember { mutableStateOf(0) }
                    val ringColor = remember { mutableStateOf(0) }
                    val colorChange = { rectC:Int?, ringC:Int? ->
                        if (rectC != null) {
                            rectColor.value = rectC
                        }
                        if (ringC != null) {
                            ringColor.value = ringC
                        }
                    }
                    ColorPicker(modifier = Modifier.padding(32.dp),colorChange)

                    Row(modifier = Modifier.fillMaxWidth()) {
                        Box(modifier = Modifier
                            .size(100.dp)
                            .background(color = Color(rectColor.value)))
                        Box(modifier = Modifier
                            .size(100.dp)
                            .background(color = Color(ringColor.value)))
                    }

                    Button(onClick = { colorPicker.show() }) {

                    }
                }
                colorPicker.InitColorPickerMenu()

            }
        }
    }
}